package com.example.lanouhn.bantangapp.activities.activities;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;

import com.example.lanouhn.bantangapp.R;
import com.yongchun.library.view.ImageSelectorActivity;

import java.util.ArrayList;

/**
 * Created by lanouhn on 16/7/23.
 */
public class ShowDialog_Avatar extends Activity {
    private LinearLayout setphoto;//设置头像
    private LinearLayout setname;//设置昵称和个性签名
    private LinearLayout setcanale;//取消
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题
        setContentView(R.layout.dialog_avatar_photo);
        //找到控件
        setphoto= (LinearLayout) findViewById(R.id.setphoto);
        setname= (LinearLayout) findViewById(R.id.setname);
        setcanale= (LinearLayout) findViewById(R.id.canale);
        initLinstener();
    }
//监听事件点击
    private void initLinstener() {
        //修改头像
        setphoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                ImageSelectorActivity.start(ShowDialog_Avatar.this, 9, ImageSelectorActivity.MODE_SINGLE, true, true, true);
            }
        });
        //修改昵称和个性签名
        setname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(ShowDialog_Avatar.this,ShowDialog_Avatar_Name.class);
                startActivityForResult(it,199);

            }
        });
        //取消
        setcanale.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

//与dialog中修改昵称和个性签名的联动 设置过后点击直接关闭dialog
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
         // finish();
            //判断当前应用是否已经获得了相关的权限
            if (ContextCompat.checkSelfPermission(ShowDialog_Avatar.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                //申请相关权限
                ActivityCompat.requestPermissions(ShowDialog_Avatar.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
            }
            if (resultCode == RESULT_OK && requestCode == ImageSelectorActivity.REQUEST_IMAGE) {
                ArrayList<String> images = (ArrayList<String>) data.getSerializableExtra(ImageSelectorActivity.REQUEST_OUTPUT);

            }
        }

    }



